<!doctype html>

<%@LANGUAGE="JScript" %>
<!--#include file ="Includes/JSON2.asp"-->
<!--#include file ="Includes/User.asp"-->
<!--#include file ="Includes/DB.asp"-->

<%

var action = "" + Request.QueryString("action");

switch(action){
	case "freeusername":
		User.AllUsers.Remove(Request.QueryString("FreeUserName"));
		
		%>
			<SCRIPT type="text/javascript">
				window.location.href = "admin.asp";
			</SCRIPT>
		<%
		Response.End();
		break;
		
	case "messagetousers":
		
		var fs = Server.CreateObject("scripting.filesystemobject");
		var filepath = Server.MapPath("access/backend/Message.txt");
		var tf = fs.OpenTextFile(filepath, 2, true);
		var msg = "" + Request.QueryString("MessageToUsers")
		
		tf.WriteLine(msg);
		tf.Close();
		%>
			<SCRIPT type="text/javascript">
				alert("** Message Set. Users will see it when their application refreshes\nMost likely within the next minute. **");
				window.location.href = "admin.asp";
			</SCRIPT>
		<%
		Response.End();
		break;
	
	case "saveexcelfilename":
		var fileNameFormat = "" + Request.QueryString("filename");

		if(fileNameFormat != "undefined"){
			fileNameFormat = fileNameFormat.replace("_", " ");
		
			db = new DB.DataCall();
			db.QueryName = "saveExcelFileNameFormat";
			db.ConnectionString = DB.ConnectionStrings.Hub;
			db.CommandType = DB.CommandTypes.StoredProc;
			db.AddParameter("@FileNameFormat", DB.DataTypes.String, fileNameFormat);

			db.Execute();
			
			if(db.Success){
				%>
					<SCRIPT type="text/javascript">
						alert("FileName Format Saved");
						window.location.href = "admin.asp";
					</SCRIPT>
				<%
			}
			else{
				%>
					<SCRIPT type="text/javascript">
						alert("FileName Format Failed To Save Due To The Following Error:\n<%= db.ErrorMessage %>");
						window.location.href = "admin.asp";
					</SCRIPT>
				<%
			}		
		}
		else{
			%>
				<SCRIPT type="text/javascript">
					alert("FileName Format Failed To Save Due To The Following Error:\n<%= db.ErrorMessage %>");
					window.location.href = "admin.asp";
				</SCRIPT>
			<%
		}	

		Response.End();
		break;
		
	default:
		db = new DB.DataCall();
		db.QueryName = "getExcelFileNameFormat";
		db.ConnectionString = DB.ConnectionStrings.Hub;
		db.CommandType = DB.CommandTypes.StoredProc;
		
		var fileNameFormat = "";
		
		db.Execute();
		if(db.Success){
			db.RecordSet.MoveFirst();
			fileNameFormat = db.RecordSet.fields("filenameformat").value;
		}
		
		var fs = Server.CreateObject("scripting.filesystemobject");
		var filepath = Server.MapPath("access/backend/Message.txt");
		var msgFile = fs.OpenTextFile(filepath);
		var msgToUsers = ""; 
		if(!msgFile.AtEndOfStream){
			msgToUsers = msgFile.ReadLine();
		}

		msgFile.Close();		
		
		break;
}



%>






<HTML XMLNS="http://www.w3.org/1999/xhtml">
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1" />
<TITLE>AdminPanel</TITLE>
<link href="UniversalStyleSheet.css" rel="stylesheet" type="text/css" />

<SCRIPT type="text/javascript">
function BtnExcel_click()
    {
	url="ExcelReport.asp";
	params="height=725, width=1000,status=no,resizable=yes,scrollbars=yes";
	window.open(url,"ExcelReport",params);
    }

function OpenEditFileName()
    {
	fn=document.ExcelForm.FileNameFormat.value;
	url="EditFileNameFormat.asp?filename=" + fn;
	params="width=500,height=150,screenX=200,screenY=200";
	window.open(url,"EditFileName",params);
	}


function SetMessageToUsers()
    {
	msg=document.getElementById("MessageToUsers").value;
	
	message=escape(msg)
	window.location.href="admin.asp?action=messagetousers&MessageToUsers=" + message;
	}

function ReleaseUser(user)
    {
	window.location.href="admin.asp?action=freeusername&FreeUserName=" + user;
	}


function SaveFileName_click()
    {
	fn=document.getElementById("FileNameFormat").value;
	filename=fn.replace(" ","_");
	window.location.href="admin.asp?action=saveexcelfilename&filename=" + filename;
	}

</SCRIPT>

</HEAD>

<BODY>

<TABLE WIDTH="740" BORDER="0" CELLSPACING="0" CELLPADDING="0">
  <TR>
    <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableUpperLeft.png"></TD>
    <TD WIDTH="700" HEIGHT="20" BACKGROUND="Images/TableUpperMiddle.png"></TD>
    <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableUpperRight.png"></TD>
  </TR>
  <TR>
    <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableMiddleLeft.png"></TD>
    <TD BGCOLOR="#FFFFFF">
	<TABLE WIDTH="92%" BORDER="0" CELLPADDING="0" CELLSPACING="1" BGCOLOR="#009900">
  <TR>
    <TD WIDTH="22%" BGCOLOR="#FFFFFF" CLASS="TableTitles">Users Online </TD>
    <TD WIDTH="78%" BGCOLOR="#FFFFFF" CLASS="TableTitles">
		<TABLE WIDTH="140" BORDER="1" CELLPADDING="0" CELLSPACING="0" BORDERCOLOR="#009900" ID="Userstable">
			<% //fill table of users 
				var ListAllUsers = User.AllUsers.ToList();
				var x = 0

				while(x < ListAllUsers.length){
					%>
						<TR>
							<TD WIDTH="73" ALIGN="center">
								<%=ListAllUsers[x] %></TD>
							<TD WIDTH="31">
								<INPUT NAME="button" TYPE="button" CLASS="buttons" TITLE="Clicking 'Release' Will Log Out Of This Application The User That Is To The Left Of This Button, Causing That Users Screen To Revert Back To The Log-In Screen When That Users Application Refreshes (SomeTime Within This Minute)" onClick="ReleaseUser('<%= ListAllUsers[x] %>')" VALUE="Release"/>
							</TD>
						</TR>
					<%
  					x += 1;
				}
			%>
    </TABLE></TD>
  </TR>
  <TR>
    <TD BGCOLOR="#FFFFFF" CLASS="TableTitles">Message To Users<BR>
      (100 characters Max) </TD>
    <TD BGCOLOR="#FFFFFF" CLASS="TableTitles">
			<INPUT NAME="MessageToUsers" TYPE="text" ID="MessageToUsers" SIZE="60" MAXLENGTH="100" STYLE="background-color:#FFFF99" VALUE="<%= msgToUsers %>"/>
			<INPUT NAME="BtnSet" TYPE="button" CLASS="buttons" ID="BtnSet" 
				TITLE="Clicking 'Set' Will Set The Message Currently Typed Into The Text Box To The Left As The Message That Is Displayed To All Users Of This Application Viewed In The Center Of The Application Header Bar" 
				onClick="SetMessageToUsers()" 
				VALUE="Set" />

			<INPUT NAME="BtnItalic" TYPE="button" CLASS="buttons" ID="BtnItalic" VALUE="I" onClick="javascript:InsertTag(this.form.MessageToUsers,'<i>','</i>')" />
	</TD>
  </TR>
  <TR>
    <TD BGCOLOR="#FFFFFF" CLASS="TableTitles">Excel Report<BR>
      (Opens in separate window) </TD>
    <TD BGCOLOR="#FFFFFF" CLASS="TableTitles">
      <INPUT NAME="BtnExcel" TYPE="button" CLASS="buttons" ID="BtnExcel" TITLE="Click 'Report Maker' To Open The Report Making Tool Used To Create Excel Reports Out Of Ticket Data For A Specified TimeFrame" onClick="BtnExcel_click()" VALUE="ReportMaker">

        <BR>
        <BR>
        FileName Format 
        <INPUT NAME="FileNameFormat" TYPE="text" ID="FileNameFormat" SIZE="50" VALUE="<%= fileNameFormat %>" STYLE="background-color:#FFFF99">
        <INPUT NAME="BtnSaveFileName" TYPE="submit" CLASS="buttons" ID="BtnSaveFileName" TITLE="Clicking 'Save' Will Save What Is Currently Entered Into The TextBox To The Left As the Format In Which Excel Reports' FileNames Will Be Named" onClick="SaveFileName_click()" VALUE="Save">
        <INPUT NAME="BtnEditFileName" TYPE="button" CLASS="buttons" ID="BtnEditFileName" TITLE="Clicking 'Edit' Will Open A Pop-Up Window Allowing You A More Advanced Method Of Creating The Format In Which Excel Reports' FileName Will Appear" onClick="OpenEditFileName()" VALUE="Edit">
		<BR>
	</TD>
  </TR>
</TABLE>
   </TD>
    <TD WIDTH="20" BACKGROUND="Images/TableMiddleRight.png"></TD>
  </TR>
  <TR>
    <TD WIDTH="20" HEIGHT="20" BACKGROUND="Images/TableLowerLeft.png"></TD>
    <TD WIDTH="700" HEIGHT="20" BACKGROUND="Images/TableLowerMiddle.png"></TD>
    <TD WIDTH="20" BACKGROUND="Images/TableLowerRight.png"></TD>
  </TR>
</TABLE>

</BODY>
</HTML>
